home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / music4c.sit / Music4C Folder / orchestras / ReadSD_2_File.c < prev   
Text File  |  1990-09-11  |  3KB  |  126 lines

  1. /* this instrument just reads in a Sound Designer II¬ format sound file
  2. and swaps the channels around (L becomes R and R becomes L).
  3. */
  4. /*
  5. * ⌐ Graeme Gerrard 1990
  6. * Faculty of Music, University of Melbourne
  7. * Parkville Victoria 3052 Australia.
  8. *
  9. * ARPANET: grae@murdu.ucs.unimelb.edu.au
  10. * telephone: (613) 344 4127, Fax: (613) 344 5104
  11. */
  12.  
  13.  
  14.  
  15. #define    READTYPE    1    /* type of instrument */
  16.  
  17. #include    <math.h>
  18. #include    "Music4c.h"
  19. #include    "ugens.h"
  20. #include    "orch.h"
  21. #include    "Music4C_Prototype.h"
  22.  
  23.  
  24. static    double E_buf[512];
  25. static    int    E_buflen;
  26. static    double    E_ptr;
  27. static    double    E_si;
  28. static    double    Sig;
  29. static    ParmBlkPtr    E_myPBlkPtr;
  30. static    ParamBlockRec        E_myPBlk;
  31. static    long StartSamp, EndSamp;
  32. static    double SampPtr;
  33.  
  34. Boolean    SetSFDir(Str255, long *);
  35. extern    long    SoundFileDirID;
  36. extern    Str255    SFDirectoryName;
  37. extern    Str255    theMess1;
  38. extern    OSErr    theErr;
  39. extern    DialogPtr    thePass3DialogPtr;
  40. extern    void    DisplayDialog(DialogPtr);
  41.  
  42.  
  43.  
  44. void initl()
  45. {
  46.  
  47.     Point    where;
  48.     SFTypeList    types;
  49.     SFReply        theFileReply;
  50.     long        nBytes;
  51.  
  52.     E_buflen = 512;
  53.     E_myPBlkPtr = &E_myPBlk;
  54.     
  55.     /* set up soundfile directory*/
  56.     SetSFDir(SFDirectoryName, &SoundFileDirID);
  57.     
  58.     SetPt(&where, 100, 100);
  59.     types[0] = 'Sd2f';
  60.     SFGetFile(where, NIL, NIL, 1, types, NIL, &theFileReply);
  61.     if(!theFileReply.good) {
  62.         FixUp();
  63.         CleanUp(FALSE);
  64.     }
  65.     DisplayDialog(thePass3DialogPtr);
  66.     E_myPBlkPtr->ioParam.ioNamePtr = (StringPtr)theFileReply.fName;
  67.     E_myPBlkPtr->ioParam.ioVRefNum = NIL;
  68.     E_myPBlkPtr->ioParam.ioVersNum = NIL;
  69.     E_myPBlkPtr->ioParam.ioPermssn = fsRdPerm;
  70.     theErr = PBOpen(E_myPBlkPtr, FALSE);
  71.     if ( theErr != noErr ) {
  72.         PstringCopy((char *)theMess1, "\pError opening file");
  73.         OSError(theMess1, theFileReply.fName, theErr);
  74.     }
  75.  
  76.     E_myPBlkPtr->ioParam.ioCompletion = NIL;
  77.     PBGetEOF(E_myPBlkPtr, FALSE);
  78.     nBytes = (long)E_myPBlkPtr->ioParam.ioMisc;
  79. }
  80.  
  81. void setup()
  82. {
  83.  
  84.     switch( instype ) {
  85.         case    READTYPE:
  86.  
  87.             E_si = p[4];                    /* sample increment */
  88.             SampPtr = p[5];        /* start sample in file */
  89.             StartSamp = (long)SampPtr;
  90.             if ( !SF_SD_2_ReadSet( E_buf, E_buflen, &E_ptr, E_myPBlkPtr, &SampPtr, &StartSamp, &EndSamp) ) {
  91.                 fprintf(stderr,"bad file name?\n");
  92.             }
  93.             break;
  94.         default:
  95.             fprintf(stderr, "Wrong file type\n");
  96.     }
  97.  
  98. }
  99.  
  100. void orch()
  101. {
  102.     switch( instype ) {
  103.         case    READTYPE:
  104.             Sig = SF_SD_2_Read(E_myPBlkPtr, E_si, E_buf, E_buflen, &E_ptr, &SampPtr, &StartSamp, &EndSamp);
  105.             Stereo(Sig, 0.0);
  106.             Sig = SF_SD_2_Read(E_myPBlkPtr, E_si, E_buf, E_buflen, &E_ptr, &SampPtr, &StartSamp, &EndSamp);
  107.             Stereo(Sig, 1.0);
  108.             break;
  109.         default:
  110.             fprintf(stderr, "Wrong instrument type\n");
  111.     }
  112. }
  113. void    ter()
  114. {
  115. }
  116.  
  117.  
  118.  
  119. void final()
  120. {
  121. /* called at the end of the synth run.
  122. *  close any files etc. you haven't already closed here.
  123. */
  124.     PBClose(E_myPBlkPtr, FALSE);
  125. }
  126.